import baseRequest from '../../request'
import {translateJSDOM} from '../../tool'

interface announceListConfig {
    teach: any[],
    announce: any[],
    notice: any[]
}

export const getAnnounceLinks = () => {
    return new Promise(async (resolve) => {

        let announceList:announceListConfig = {
            teach: [],
            announce: [],
            notice: []
        }

        let res = await baseRequest.get('http://www.wuyiu.edu.cn/jwc/', '')

        // console.log(res.data);
        const $: any = translateJSDOM(res.data)

        // 获取到表格dom节点，并遍历每一个tr(每一行进行) => 获取内容
        $("#wp_news_w20 > .wp_article_list > .list_item > .fields > .Article_Title > a").each((index: number, item: any) => {
            let res = {
                id: index,
                content: $(item).text(),
                link: 'http://www.wuyiu.edu.cn' + $(item).attr('href')
            }
            announceList.teach.push(res)
            // console.log($(item).children());
            // let s= $(item).children();
            // console.log(s);
        })

        $("#wp_news_w21 > .wp_article_list > .list_item > .fields > .Article_Title > a").each((index: number, item: any) => {
            let res = {
                id: index,
                content: $(item).text(),
                link: 'http://www.wuyiu.edu.cn' + $(item).attr('href')
            }
            announceList.announce.push(res)
            // console.log($(item).children());
            // let s= $(item).children();
            // console.log(s);
        })

        $("#wp_news_w22 > .wp_article_list > .list_item > .fields > .Article_Title > a").each((index: number, item: any) => {
            let res = {
                id: index,
                content: $(item).text(),
                link: 'http://www.wuyiu.edu.cn' + $(item).attr('href')
            }
            announceList.notice.push(res)
            // console.log($(item).children());
            // let s= $(item).children();
            // console.log(s);
        })

        // console.log(announceList);
        resolve(announceList)
    })
}



